<?php 
$pathArr = explode("/", $_SERVER["PHP_SELF"]);
$contextPath = $pathArr[1];
$rootPath = $_SERVER["DOCUMENT_ROOT"];
include_once $rootPath . "/" . $contextPath . "/apps/ManagerIUDS.php";
$managerIUDS = new ManagerIUDS();

$predicateData = $managerIUDS->queryData("predicate_name,price,predicate_id", "predicate", "", "2", "");
$price = $_GET["price"];
if($price == "" || $price == null){
	$price = "";
}
$data = $_GET["data"];

if($data == "" || $data == null){
	$data = "";
}
	$explodeData = explode(",", $data);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>.: Predicate Detail :.</title>
<?php
require_once($rootPath . "/" . $contextPath . "/includes/css_inc.php");
require_once($rootPath . "/" . $contextPath . "/includes/js_inc.php");
?>
<script>
	function savePrice(){
		var data = document.getElementById("data").value;
		var predicateName = document.getElementById("predicate_name").value;
		window.opener.document.prdicate_frm.price.value = document.getElementById("price").value;
		window.opener.document.prdicate_frm.predicate_data.value = data.substring(0,data.length-2);
		window.opener.document.prdicate_frm.predicate_list.value = predicateName.substring(0,predicateName.length-2);
		window.close();
	}
	function checkData(predicateData){
		var sum =0;
		var data = "";
		var predicateName = "";
		 for(var i=0;i<frm1.elements.length;i++){
			if(frm1.elements[i].type=="checkbox" && frm1.elements[i].value.indexOf("|") > 0){
				if(frm1.elements[i].checked){
					mySplit = frm1.elements[i].value.split("|");
					sum = parseInt(sum) + parseInt(mySplit[0]);
					data += mySplit[1]+", ";
					predicateName += mySplit[2]+", ";
				}
			}
		}
		document.getElementById("price").value = sum;
		document.getElementById("data").value = data;
		document.getElementById("predicate_name").value = predicateName;
	}
</script>
</head>
<body>
<center>
<form name="frm1">
<table border="0" width="60%">
	<thead class="ui-widget">
		<tr class="ui-widget-header">
			<th colspan="3" align="left">&nbsp;&nbsp;&nbsp;รายละเอียดการวินิจฉัยสัตว์เลี้ยง</th>
		</tr>
	</thead>
	<tbody class="ui-widget-content">
	<?php 
	$i=0;
		foreach ($predicateData as $value){
	?>
		<tr>
			<td width="15%" align="center">
				<input type="checkbox" name="predicate_data" id="predicate_data" onclick="checkData(this)" 
				<?php 
					for($j=0;$j<sizeof($explodeData);$j++){ 
						if($explodeData[$j] == $value["predicate_id"]){
							echo 'checked="checked"';
						}
					}
				?>
				value="<?=$value["price"]?>|<?=$value["predicate_id"]?>|<?=$value["predicate_name"]?>">
			</td>
			<td>
				<?=$value["predicate_name"]?>
			</td>
			<td align="left" width="10%">
				ราคา : <?=$value["price"]?>
			</td>
		</tr>
	<?php 
		$i++;}
	?>
		<tr>
			<td align="center" width="15%">ราคา : </td>
			<td colspan="2"><input type="text" name="price" id="price" onkeypress="return numbersOnly(event, false);" value="<?=$price?>"></td>
		</tr>
		<tr>
			<td colspan="3" align="center">
			<input  type="button" name="save_data" id="save_data" value="บันทึก" onclick="savePrice()">
			<input type="button" value="ยกเลิก"	onclick="window.close();"></td>
		</tr>
	</tbody>
</table>
<input type="hidden" name="data" id="data" value="<?=$data?>">
<input type="hidden" name="predicate_name" id="predicate_name" value="">
</form>
</center>
</body>
</html>
